﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CRS.Web.UserControls
{
    public partial class DateCtl : System.Web.UI.UserControl
    {
        public string KeyVal
        {
            get
            {
                var obj = ViewState["KeyVal"];
                obj = obj ?? "";
                return obj.ToString();
            }
            set { ViewState["KeyVal"] = value; }
        }

        private void SetDefaultVal()
        {
            if (txtCalendar.Text.Length == 0)
            {
                txtCalendar.Text = DateTime.Now.ToString("yyyy-MM-dd");
            }
        }
        public string Text
        {
            get
            {
                SetDefaultVal();
                return txtCalendar.Text;
            }
            set
            {
                txtCalendar.Text = value;
                SetDefaultVal();
            }
        }
        public bool Enabled
        {
            get { return txtCalendar.Enabled; }
            set { txtCalendar.Enabled = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                SetDefaultVal();
        }
    }
}
